// pages/order/orderDetail/orderDetail.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseImgUrl: getApp().globalData.IMG_URL,
    orderInfo: { orderPayPrice: 0, orderAllPrice: 0, deliveryTime: '00:00', delivery: false },
    orderNo: "",
    // 操作部分
    selectedTotalPrice: 0,
    selectedOldTotalPrice: 0,
    selectedTotalNum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.error("options ==> " + JSON.stringify(options))
    var orderNoStr = options.orderNo
    this.setData({ orderNo: orderNoStr })
    // 获取信息
    this.getOrderDetailInfo(orderNoStr!!)
    // console.error("data ==> " + JSON.stringify(this.data))
  },
  onShow(){
    try {
      wx.setStorage({key: 'storeNeedCleanAct', data: 1})
    } catch (error) {
    }
  },
  getOrderDetailInfo(orderNo: string): void {
    // console.error("orderNo ==> " + orderNo)
    var that = this
    const token = wx.getStorageSync('token')
    const preUrl = getApp().globalData.SERVER_URL
    const url = preUrl + "fc/order/customer/findByOrderNo"
    wx.request({
      url: url,
      method: 'GET',
      data: {
        orderNo: orderNo
      },
      header: {
        'content-type': 'application/json', // 默认值
        'X-Access-Token': token
      },
      success(res: any) {
        console.error("getOrderDetailInfo ==> " + JSON.stringify(res.data))
        wx.stopPullDownRefresh()
        if (res.data.code == 200) {
          const length = res.data.result.goodsList.length
          for (let index = 0; index < length; index++) {
            const goods = res.data.result.goodsList[index]
            if (goods != null) {
              const cover = goods.goodsCover;
              if (cover.includes(',')) {
                const firstIndex = cover.indexOf(',');
                const coverReal = cover.substring(0, firstIndex);
                goods.goodsCover = coverReal
              } else {
                goods.goodsCover = cover
              }
            }
          }
          that.setData({ orderInfo: res.data.result })
        } else {
          console.info(JSON.stringify(res))
        }
      },
    })
  },
})